/*
 * Client.cpp
 *
 *  Created on: Apr 9, 2011
 *      Author: pablo
 */

#include "Client.h"

using namespace std;

Client::Client(string name) {
	this->setPid(getpid());

}

Client::~Client() {
//	this->sharedMemoryClient.liberar();
}

string Client::getName(){
	return this->name;
};

void Client::setName(string name){
	this->name = name;
}

int Client::getPidServer(){
 return this->pidServer;
}
void Client::setPidServer(int pidServer){
 this->pidServer = pidServer;
}

int Client::obtenerServerPid(){
	this->sharedMemoryServer.crear((char*)RUTA_ARCHIVO_CONFIGURACION_SERVER,'K',IPC_EXCL);
	this->setPidServer(this->sharedMemoryServer.leer());
//	this->sharedMemoryServer.liberar();
	return this->getPidServer();
}

void Client::alocarClientPid(){
	this->sharedMemoryClient.crear((char*)RUTA_ARCHIVO_CONFIGURACION_CLIENTE,'K',IPC_CREAT);
	this->sharedMemoryClient.escribir(this->getPid());
//	this->sharedMemoryClient.liberar();
}

int main(){
	Client* client = new Client("pepito");
	client->alocarClientPid();
	sleep(5);
	cout << "Cliente: Ya escribi mi PID!!" << endl;
	int pidServer = client->obtenerServerPid();
	cout << "El pid del server es..." << pidServer << endl;
	delete client;

	return 0;
}

